app.controller('PriceModalCtrl', function ($scope, $modalInstance, $modal, toaster, param, ajax) {
	var inserter = new Req.POST({ resource: $scope.resource });

	$scope.submitting = false;
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}

	$scope.ok = function () {
		if ($scope.myForm.$valid) {
			$modalInstance.close($scope.param);
		}
	};

	$scope.total = 0;

	$scope.mono = 0;

	$scope.rule = function () {
		if ($scope.myForm.$valid) {
			if ($scope.number <= 0 || $scope.number == undefined) {
				toaster.pop('warning', '提示', '请输入正确的人数！');
				return;
			} else {
				inserter.fields = $scope.param.data;
				inserter.resource = 'price/rt/' + $scope.number + '/rule';
				ajax.call(inserter).then(function (result) {
					if (result.code == 200) {
						$scope.total = result.result.total;
						$scope.mono = result.result.mono;
					} else {
						toaster.pop('error', '错误', result.result);
					}
				}, function () {
					toaster.pop('error', '错误', '验证失败。');
				});
			}
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
		$scope.submitting = false;
	};
});